import 'dart:convert';

import 'package:concierge/app/models/user_bean.dart';
import 'package:shared_preferences/shared_preferences.dart';

Future saveUser(UserBean? user) async {
  var sp = await SharedPreferences.getInstance();
  if (user == null) {
    await sp.remove("user");
  } else {
    await sp.setString("user", jsonEncode(user.toJson()));
  }
}

Future<UserBean?> getUser() async {
  var sp = await SharedPreferences.getInstance();
  var userStr = sp.getString("user");
  if (userStr == null) {
    return null;
  } else {
    return userBeanFromJson(userStr);
  }
}
